<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
            padding-left: 30px;
        }
        .my-checkbox{
            display: inline-block;
            border: 2px solid #999;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            margin: 0px 20px;
        }
        .my-checkbox input{
            display: none;
        }
        .my-checkbox .pot{
            display: inline-block;
            width: 100%;
            height: 100%;
            background-color: green;
            border-radius: 50%;
            transform: scale(0.6);
            display: none;
        }
        .my-checkbox input:checked + span{
            display: inline-block;
        }
        .cbox{
            border: 1px solid #999;
            padding: 20px;
            margin: 10px 0px;
        }
    </style>
</head>
<body>
    <div id="app">
        <pre>
        组件标签的v-model定义：因为v-model指令为语法糖指令，所以组件v-model操作等同于 v-bind + v-on 操作
            1、v-bind完成默认属性 model-value = modelValue 绑定
            2、v-on完成默认事件绑定 update:model-value = update:modelValue 绑定
        
        一个组件同时定义多个v-model时，可以通过v-model组件独享参数规则 : 修改拦截属性名和拦截事件名
        </pre>
        <p>flag:{{ flag }}</p>
        <input type="checkbox" v-model="flag" >
        <br>
        <my-checkbox :model-value="flag" @update:model-value=" flag=$event "></my-checkbox>
        <br>
        <my-checkbox v-model="flag"></my-checkbox>
        <hr>
        <p>msg:{{ msg }}</p>
        <p>info:{{ info }}</p>
        <comp-a v-model="msg" v-model:info="info"></comp-a>
    </div>

    <script type="text/x-template" id="MyCheckbox">
        <label class="my-checkbox">
            <input type="checkbox" v-model="newArg" v-bind="$attrs">
            <span class="pot"></span>
        </label>
    </script>
    <script type="text/x-template" id="compA">
        <div class="cbox">
            <p>modelValue:{{ modelValue }}</p>
            <input type="text" v-model="msg">
            <p>info:{{ info }}</p>
            <input type="text" v-model="newInfo">
        </div>
    </script>
    <script type="module">
        // 加载 Vue3 的ESM 模块文件
        import { createApp } from "../../assets/vue3/vue.esm-browser.js"

        const MyCheckbox = {
            template:"#MyCheckbox",
            emits:["update:modelValue"],
            props: {
                modelValue: {},
            },
            computed: {
                newArg:{
                    get(){
                        return this.modelValue;
                    },
                    set(nv){
                        this.$emit("update:modelValue",nv)
                    }
                }
            },
        }

        const CompA = {
            template:"#compA",
            emits:["update:modelValue","update:info"],
            props: {
                modelValue: {},
                info:{}
            },
            computed: {
                msg:{
                    get(){
                        return this.modelValue
                    },
                    set(nv){
                        this.$emit("update:modelValue",nv)
                    }
                },
                newInfo:{
                    get(){
                        return this.info
                    },
                    set(nv){
                        this.$emit("update:info",nv)
                    }
                }
            },
        }

        createApp({
            components: {
                MyCheckbox,CompA
            },
            data(){
                return {
                    flag:false,
                    msg:"msg",
                    info:"info"
                }
            }
        }).mount("#app")
    </script>
</body>
</html>